import {
    getQuickProject
} from '../../api/pay'
import {
    dateFormat
} from '../../../utils/util'
const app = getApp()
Page({
    /**
     * 页面的初始数据
     */
    data: {
        initd: false,
        date: '',
        projectId: '',
        todo: [],
        count: 0,
        workers: [],
        quickProjectId: '',
        quickProjectName: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onShow: function () {
        if(this.data.initd)
            this.getQuickProject()
        else
            this.setData({initd: true})
    },
    onDateChange(event) {
        this.setData({
            date: event.detail
        })
        this.getQuickProject()
    },
    getQuickProject() {
        getQuickProject({
            queryDate: this.data.date
        }).then(res => {
            const dateGroup = {}
            res.dateGroup.forEach(item => {
                dateGroup[item] = 1
            })
            const list = []
            res.list.forEach(item => {
                list.push({
                    time: dateFormat('HH:MM', new Date(item.createTime)),
                    name: item.workerName + item.idCardNo.slice(-4),
                    userId: item.userId
                })
            })
            this.setData({
                todo: dateGroup,
                workers: list,
                count: res.count,
                projectId: res.projectId,
                quickProjectId: res.quickProjectId,
                quickProjectName: res.quickProjectName
            })
            console.log(this.data.todo,'todo')
        })
    },
    onGoWorker(event){
        const workerId = event.currentTarget.dataset.id
        wx.navigateTo({
            url: '/pages/worker/index/index?id=' + workerId
        })
    },
    payWage() {
        if(!this.data.projectId){
            app.toast('请至少添加一人')
            return
        }
        wx.navigateTo({
            url: '/packagePay/pages/pay-wage/pay-wage?id=' + this.data.projectId + '&type='+ 0
        })
    },
    goInvitationPoster() {
        wx.navigateTo({
            url: '/packagePay/pages/invitation-poster/invitation-poster?notRecord=1&projectId=' + this.data.quickProjectId + '&projectName=' + this.data.quickProjectName
        })
    },
    goSetUpInfo(){
        wx.redirectTo({
          url: '/packagePay/pages/fast-pay-guide/fast-pay-guide?type=' + 1,
        })
    }
})